import router from './router';
import { getCookie } from '@/utils/support.js';
import { Message } from 'element-ui';
import store from './store';
const whiteList = ['/login'];
router.beforeEach((to, from, next) => {
    console.log(to, from);

    if (getCookie("token")) {
        if (to.path == "/login") {
            next("/home");
        } else if (to.path == "/super") {

            if (getCookie('roleid') == 1) {
                next();
            } else {

                Message({
                    message: "您没有权限访问该页面，请退出后使用 超级管理员身份登录",
                    type: "error",
                    duration: 2000
                })
                store.dispatch('LOGOUT_AC');
                router.go(0);
            }
        } else {

            next();
        }
    } else {

        if (whiteList.indexOf(to.path) !== -1) {

            next();
        } else {

            next("/login");
        }
    }
})